﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Module.Core.BusinessLogic.Products;

namespace Web
{
    public partial class _default : System.Web.UI.Page
    {
        protected float Price_vat;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                DataSet ds = ProductsBL.GetProduct(1, 1, 9, 1);

                if (ds != null && ds.Tables.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        rptProduct.DataSource = ds.Tables[0];
                        rptProduct.ItemDataBound += new RepeaterItemEventHandler(rptProduct_ItemDataBound);
                        rptProduct.DataBind();

                    }                    
                }

            }
            catch (Exception)
            {                                
            }
        }

        void rptProduct_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Label lbProductName = (Label) e.Item.FindControl("lbProductName");
            DataRowView dr = (DataRowView)e.Item.DataItem;
            if(dr["ProductName"] !=null && dr["ProductName"] !="")
            {
                if(dr["ProductName"].ToString().Length > 30)
                {
                    lbProductName.Text = dr["ProductName"].ToString().Substring(0, 30)+" ...";
                }
                else
                {
                    lbProductName.Text = dr["ProductName"].ToString();
                }
            }
            if (float.Parse(dr["Price_VAT"].ToString()) > 0 && float.Parse(dr["Price"].ToString()) > 0)
            {
                Price_vat = float.Parse(dr["Price"].ToString()) - ((float.Parse(dr["Price_VAT"].ToString()) * float.Parse(dr["Price"].ToString())) / 100);
            }
            else
            {
                Price_vat = float.Parse(dr["Price"].ToString());
            }
            Label lbgiaban = (Label) e.Item.FindControl("lbgiaban");
            lbgiaban.Text = "Giá bán: "+ Price_vat.ToString() +" (VND)";
        }
    }
}